//
//  WEXTabBarController.m
//  microBlog_oc
//
//  Created by apple on 16/4/17.
//  Copyright © 2016年 Hill. All rights reserved.
//

#import "WEXTabBarController.h"
#import "WEXHomeViewController.h"
#import "WEXMessageViewController.h"
#import "WEXDiscoverViewController.h"
#import "WEXProfileViewController.h"
#import "WEXTabBar.h"

@interface WEXTabBarController ()<WEXTabBarDelegate>

@end

@implementation WEXTabBarController


-(void)viewDidLoad {
    
    [super viewDidLoad];
//    初始化一个自定义
    WEXTabBar *tabBar = [[WEXTabBar alloc] init];
    tabBar.delegates = self;

//    设置自定义的tabBar
    [self setValue:tabBar forKey:@"tabBar"];
    
    
    
//    实例化控制器
    WEXHomeViewController *homeVc = [[WEXHomeViewController alloc] init];
    WEXMessageViewController *messageVc = [[WEXMessageViewController alloc] init];
    WEXDiscoverViewController *discoverVc = [[WEXDiscoverViewController alloc] init];
    WEXProfileViewController *profileVc = [[WEXProfileViewController alloc] init];
    
//    添加子控制器
    [self addChildViewController:homeVc withTitle:@"主页" withImgName:@"tabbar_home"];
    [self addChildViewController:messageVc withTitle:@"信息" withImgName:@"tabbar_message_center"];
    [self addChildViewController:discoverVc withTitle:@"发现" withImgName:@"tabbar_discover"];
    [self addChildViewController:profileVc withTitle:@"我" withImgName:@"tabbar_profile"];
    
}

- (void)addChildViewController:(UIViewController *)childController withTitle:(NSString *)title withImgName:(NSString *)imgName {
    
    childController.title = title;
    childController.tabBarItem.image = [UIImage imageNamed:imgName];
    
    
    NSString *selectedImageName = [NSString stringWithFormat:@"%@_selected",imgName];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor orangeColor]};
    
    
    [childController.tabBarItem setTitleTextAttributes:attributes forState:UIControlStateSelected];
    
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:childController];
    
    [self addChildViewController:navController];
    
}

# pragma mark -
# pragma mark tabBar代理方法
- (void)tabBar:(WEXTabBar *)tabBar{
    
    NSLog(@"我被调用了");
}

@end
